package doj;

import static org.junit.Assert.assertEquals;

import robocode.BattleResults;
import robocode.control.testing.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;

/**
 * JUnit testing.
 * Robot should beat SittingDuck every time.
 * 
 * @author Jordan Do
 */
public class TestSittingDuck extends RobotTestBed {

  /**
   * Specifies that SittingDuck and DojBot are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,doj.DojBot";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * The actual test, which asserts that DojBot wins every round.
   * @param event Details about the completed battle.
   */
  @Override
 public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is DojBot (not strictly necessary, but illustrative).
    BattleResults results = battleResults[1];
    String robotName = results.getTeamLeaderName();
    assertEquals("Check that results[1] is DojBot", robotName, "doj.DojBot*");
    //Check to make sure KillBot won every round.
    assertEquals("Check DojBot winner", results.getFirsts(), getNumRounds());
  } 
}

